package cn.ycc1.lianzitu.handler;

import cn.ycc1.lianzitu.util.GlobalException;
import cn.ycc1.lianzitu.util.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @author ycc
 * @date 2025/01/08 11:51
 */
@Slf4j
@RestControllerAdvice
public class GlobalExceptionHandler {
    // 全局异常拦截
    @ExceptionHandler(GlobalException.class)
    public Result handlerException(GlobalException exception) {
        log.debug("global exception", exception);
        Result<Object> failed = Result.error(exception.getCode(), exception.getMessage());
        failed.setData(exception.getData());
        return failed;
    }
}

